@echo off
title Scheduled Shutdown Tool
echo ================================================
echo            Scheduled Shutdown Tool
echo ================================================
echo.
echo Please select an option:
echo 1: Schedule shutdown (0-6 hours)
echo 2: Cancel scheduled shutdown
echo 3: Exit
echo.
set /p option=Enter your choice (1-3): 

:: Validate main menu input
if "%option%"=="1" (
    goto schedule
) else if "%option%"=="2" (
    goto cancel
) else if "%option%"=="3" (
    echo Exiting the program...
    pause
    exit
) else (
    echo Invalid choice. Please enter 1, 2, or 3.
    pause
    exit
)

:schedule
echo ================================================
echo Schedule shutdown: Enter the time (0-6 hours)
echo 0: Shutdown immediately
echo 1: Shutdown in 1 hour
echo 2: Shutdown in 2 hours
echo 3: Shutdown in 3 hours
echo 4: Shutdown in 4 hours
echo 5: Shutdown in 5 hours
echo 6: Shutdown in 6 hours
echo.
set /p choice=Enter your choice (0-6): 

:: Validate input for scheduling
if "%choice%"=="" (
    echo Invalid input. Please enter a number between 0 and 6.
    pause
    exit
)

if "%choice%" geq "0" if "%choice%" leq "6" (
    :: Calculate the time in seconds (1 hour = 3600 seconds)
    set /a time_in_seconds=%choice%*3600
    
    if "%choice%"=="0" (
        echo Shutting down immediately...
        shutdown /s /t 0
    ) else (
        echo The computer will shut down in %choice% hour(s) (%time_in_seconds% seconds).
        shutdown /s /t %time_in_seconds%
    )
) else (
    echo Invalid input. Please enter a number between 0 and 6.
    pause
    exit
)

pause
exit

:cancel
echo ================================================
echo Canceling scheduled shutdown...
shutdown /a >nul 2>&1
if %errorlevel%==0 (
    echo Scheduled shutdown has been successfully canceled.
) else (
    echo No scheduled shutdown was found to cancel.
)
pause
exit
